package com.eclipse.training.extensions.views;

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

import com.eclipse.training.extensions.ui.ModelContentProvider;
import com.eclipse.training.extensions.ui.ModelLabelProvider;
import com.eclipse.training.models.ModelProvider;

public class TrainingTreeView extends ViewPart {

	/**
	 * The ID of the view as specified by the extension.
	 */
	public static final String ID = "com.eclipse.training.extensions.views.TrainingTreeView"; //$NON-NLS-1$

	private TreeViewer viewer;

	/**
	 * The constructor.
	 */
	public TrainingTreeView() {
	}

	/**
	 * Create the viewer and initialize it. Typically this method simply calls
	 * more finely grained methods that draw part controls.
	 */
	public void createPartControl(Composite parent) {
		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		viewer.setContentProvider(new ModelContentProvider());
		viewer.setLabelProvider(new ModelLabelProvider());
		viewer.setInput(ModelProvider.getModel());

		/*
		 * For a view to be a selection provider, it must register itself as a
		 * selection provider with the view site.
		 * 
		 * Moreover, each of the objects contained in the viewer should be
		 * adaptable.
		 */
		getSite().setSelectionProvider(viewer);

	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		viewer.getControl().setFocus();
		viewer.refresh();
	}

}